package com.jxud.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

//@WebFilter(urlPatterns = "/*")   //要拦截那些请求
public class DemoFilter implements Filter {
    @Override//初始化只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init 初始化方法执行了");
    }

    @Override // 拦截到请求之后调用
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("doFilter 拦截到了请求 放行前的逻辑");
        // 拦截到之后要放行
        filterChain.doFilter(servletRequest, servletResponse);
        //放行后的代码执行完毕回到filter
        System.out.println("doFilter 拦截到了请求 放行后的逻辑");

    }

    @Override // 销毁方法 只调用一次
    public void destroy() {
        System.out.println("destroy 销毁方法执行了");
    }
}
